////////////////////////////////////////////////////////////////
// filename: world.cpp
// description: source file for the world objects class
// author: Jay Tomten (jaytomten@gmail.com)
// notes:

// namespace

// defines

// includes
#if defined(__APPLE__)
#include <SDL_image/SDL_image.h>
#else
#include <SDL/SDL_image.h>
#endif
#include <SDL/SDL.h>
#include "object.h"
#include <stdlib.h>
#include <math.h>
#include "world.h"
#include <iostream>
#include "md2/md2model.h"

// globals

////////////////////////////////////////////////////////////////
// constructor
World::World()
    {

    // use Init() or alt constructor

    }

////////////////////////////////////////////////////////////////
// alternate constructor that calls Init()
World::World(int type, float x, float y, float z)
    {

    Init(type, x, y, z);

    }

////////////////////////////////////////////////////////////////
// destructor
World::~World()
    {

    glDeleteTextures(1, &texture);
    delete v;


    }

////////////////////////////////////////////////////////////////
// Init() - set up the world we want
void World::Init(int type, float x, float y, float z)
    {

    // there must be a better way!
    switch(type)
        {
        case WORLD_LAND:
            size = 1;
            v[0].Init(-150.0f, 0.0f, 0.0f, 150.0f, 0.0f, 0.0f);
            width = 2.0;
            col.Init(1.0f, 1.0f, 1.0f, 1.0f);
            t = WORLD_LAND;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            // team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            break;
        case WORLD_BUILDING_1:
            size = 19;
            v[0].Init( 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); // box
            v[1].Init( 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f);
            v[2].Init( 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            v[3].Init( 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
            v[4].Init( 0.6, 0.0f, 0.0f, 0.6, 0.4, 0.0f); // door
            v[5].Init( 0.6, 0.4, 0.0f, 0.9, 0.4, 0.0f);
            v[6].Init( 0.9, 0.4, 0.0f, 0.9, 0.0f, 0.0f);
            v[7].Init( 0.2, 0.7, 0.0f, 0.4, 0.7, 0.0f); // window 1
            v[8].Init( 0.4, 0.7, 0.0f, 0.4, 0.8, 0.0f);
            v[9].Init( 0.4, 0.8, 0.0f, 0.2, 0.8, 0.0f);
            v[10].Init( 0.2, 0.8, 0.0f, 0.2, 0.7, 0.0f);
            v[11].Init( 0.6, 0.7, 0.0f, 0.8, 0.7, 0.0f); // window 2
            v[12].Init( 0.8, 0.7, 0.0f, 0.8, 0.8, 0.0f);
            v[13].Init( 0.8, 0.8, 0.0f, 0.6, 0.8, 0.0f);
            v[14].Init( 0.6, 0.8, 0.0f, 0.6, 0.7, 0.0f);
            v[15].Init( 0.7, 1.0f, 0.0f, 0.7, 2.0f, 0.0f); // flag
            v[16].Init( 0.7, 2.0f, 0.0f, 0.3, 2.0f, 0.0f);
            v[17].Init( 0.3, 2.0f, 0.0f, 0.3, 1.6, 0.0f);
            v[18].Init( 0.3, 1.6, 0.0f, 0.7, 1.6, 0.0f);
            width = 2.0;
            col.Init(1.0f, 1.0f, 1.0f, 1.0f);
            t = WORLD_BUILDING_1;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            break;
        case WORLD_BUILDING_2:
            size = 21;
            v[0].Init( 0.0f, 0.0f, 0.0f, 1.5, 0.0f, 0.0f); // box
            v[1].Init( 1.5, 0.0f, 0.0f, 1.5, 1.0f, 0.0f);
            v[2].Init( 1.5, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            v[3].Init( 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
            v[4].Init( 0.2, 0.0f, 0.0f, 0.2, 0.4, 0.0f); // door
            v[5].Init( 0.2, 0.4, 0.0f, 0.5, 0.4, 0.0f);
            v[6].Init( 0.5, 0.4, 0.0f, 0.5, 0.0f, 0.0f);
            v[7].Init( 0.2, 0.7, 0.0f, 0.4, 0.7, 0.0f); // window 1
            v[8].Init( 0.4, 0.7, 0.0f, 0.4, 0.8, 0.0f);
            v[9].Init( 0.4, 0.8, 0.0f, 0.2, 0.8, 0.0f);
            v[10].Init( 0.2, 0.8, 0.0f, 0.2, 0.7, 0.0f);
            v[11].Init( 0.8, 0.0f, 0.0f, 0.8, 0.8, 0.0f); // garage door
            v[12].Init( 0.8, 0.8, 0.0f, 1.3, 0.8, 0.0f);
            v[13].Init( 1.3, 0.8, 0.0f, 1.3, 0.0f, 0.0f);
            v[14].Init( 0.8, 0.4, 0.0f, 1.3, 0.4, 0.0f);
            v[15].Init( 0.8, 0.2, 0.0f, 1.3, 0.2, 0.0f);
            v[16].Init( 0.8, 0.6, 0.0f, 1.3, 0.6, 0.0f);
            v[17].Init( 0.9, 1.0f, 0.0f, 0.9, 2.0f, 0.0f); // flag
            v[18].Init( 0.9, 2.0f, 0.0f, 0.5, 2.0f, 0.0f);
            v[19].Init( 0.5, 2.0f, 0.0f, 0.5, 1.6, 0.0f);
            v[20].Init( 0.5, 1.6, 0.0f, 0.9, 1.6, 0.0f);
            width = 2.0;
            col.Init(1.0f, 1.0f, 1.0f, 1.0f);
            t = WORLD_BUILDING_2;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            break;
        case WORLD_BUILDING_3:
            size = 27;
            v[0].Init( 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f); // box
            v[1].Init( 1.0f, 0.0f, 0.0f, 1.0f, 2.0f, 0.0f);
            v[2].Init( 1.0f, 2.0f, 0.0f, 0.0f, 2.0f, 0.0f);
            v[3].Init( 0.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f);
            v[4].Init( 0.2, 0.0f, 0.0f, 0.2, 0.4, 0.0f); // door
            v[5].Init( 0.2, 0.4, 0.0f, 0.5, 0.4, 0.0f);
            v[6].Init( 0.5, 0.4, 0.0f, 0.5, 0.0f, 0.0f);
            v[7].Init( 0.2, 0.7, 0.0f, 0.4, 0.7, 0.0f); // window 1
            v[8].Init( 0.4, 0.7, 0.0f, 0.4, 0.8, 0.0f);
            v[9].Init( 0.4, 0.8, 0.0f, 0.2, 0.8, 0.0f);
            v[10].Init( 0.2, 0.8, 0.0f, 0.2, 0.7, 0.0f);
            v[11].Init( 0.6, 0.7, 0.0f, 0.8, 0.7, 0.0f); // window 2
            v[12].Init( 0.8, 0.7, 0.0f, 0.8, 0.8, 0.0f);
            v[13].Init( 0.8, 0.8, 0.0f, 0.6, 0.8, 0.0f);
            v[14].Init( 0.6, 0.8, 0.0f, 0.6, 0.7, 0.0f);
            v[15].Init( 0.2, 1.7, 0.0f, 0.4, 1.7, 0.0f); // window 3
            v[16].Init( 0.4, 1.7, 0.0f, 0.4, 1.8, 0.0f);
            v[17].Init( 0.4, 1.8, 0.0f, 0.2, 1.8, 0.0f);
            v[18].Init( 0.2, 1.8, 0.0f, 0.2, 1.7, 0.0f);
            v[19].Init( 0.6, 1.5, 0.0f, 0.8, 1.5, 0.0f); // window 4
            v[20].Init( 0.8, 1.5, 0.0f, 0.8, 1.6, 0.0f);
            v[21].Init( 0.8, 1.6, 0.0f, 0.6, 1.6, 0.0f);
            v[22].Init( 0.6, 1.6, 0.0f, 0.6, 1.5, 0.0f);
            v[23].Init( 0.7, 2.0f, 0.0f, 0.7, 3.0f, 0.0f); // flag
            v[24].Init( 0.7, 3.0f, 0.0f, 0.3, 3.0f, 0.0f);
            v[25].Init( 0.3, 3.0f, 0.0f, 0.3, 2.6, 0.0f);
            v[26].Init( 0.3, 2.6, 0.0f, 0.7, 2.6, 0.0f);
            width = 2.0;
            col.Init(1.0f, 1.0f, 1.0f, 1.0f);
            t = WORLD_BUILDING_3;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            break;
        case WORLD_BUILDING_4:
            size = 27;
            v[0].Init( 0.0f, 0.0f, 0.0f, 2.0f, 0.0f, 0.0f); // box
            v[1].Init( 2.0f, 0.0f, 0.0f, 2.0f, 1.0f, 0.0f);
            v[2].Init( 2.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f);
            v[3].Init( 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f);
            v[4].Init( 0.2, 0.0f, 0.0f, 0.2, 0.4, 0.0f); // door
            v[5].Init( 0.2, 0.4, 0.0f, 0.5, 0.4, 0.0f);
            v[6].Init( 0.5, 0.4, 0.0f, 0.5, 0.0f, 0.0f);
            v[7].Init( 0.2, 0.7, 0.0f, 0.4, 0.7, 0.0f); // window 1
            v[8].Init( 0.4, 0.7, 0.0f, 0.4, 0.8, 0.0f);
            v[9].Init( 0.4, 0.8, 0.0f, 0.2, 0.8, 0.0f);
            v[10].Init( 0.2, 0.8, 0.0f, 0.2, 0.7, 0.0f);
            v[11].Init( 0.6, 0.7, 0.0f, 0.8, 0.7, 0.0f); // window 2
            v[12].Init( 0.8, 0.7, 0.0f, 0.8, 0.8, 0.0f);
            v[13].Init( 0.8, 0.8, 0.0f, 0.6, 0.8, 0.0f);
            v[14].Init( 0.6, 0.8, 0.0f, 0.6, 0.7, 0.0f);
            v[15].Init( 1.2, 0.7, 0.0f, 1.4, 0.7, 0.0f); // window 3
            v[16].Init( 1.4, 0.7, 0.0f, 1.4, 0.8, 0.0f);
            v[17].Init( 1.4, 0.8, 0.0f, 1.2, 0.8, 0.0f);
            v[18].Init( 1.2, 0.8, 0.0f, 1.2, 0.7, 0.0f);
            v[19].Init( 1.6, 0.7, 0.0f, 1.8, 0.7, 0.0f); // window 4
            v[20].Init( 1.8, 0.7, 0.0f, 1.8, 0.8, 0.0f);
            v[21].Init( 1.8, 0.8, 0.0f, 1.6, 0.8, 0.0f);
            v[22].Init( 1.6, 0.8, 0.0f, 1.6, 0.7, 0.0f);
            v[23].Init( 0.7, 1.0f, 0.0f, 0.7, 2.0f, 0.0f); // flag
            v[24].Init( 0.7, 2.0f, 0.0f, 0.3, 2.0f, 0.0f);
            v[25].Init( 0.3, 2.0f, 0.0f, 0.3, 1.6, 0.0f);
            v[26].Init( 0.3, 1.6, 0.0f, 0.7, 1.6, 0.0f);
            width = 2.0;
            col.Init(1.0f, 1.0f, 1.0f, 1.0f);
            t = WORLD_BUILDING_4;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            break;
        case WORLD_BUNKER:
            size = 28;


            v[0].Init( 0.0f, 0.0f, 0.0f, 0.0f, 0.3, 0.0f); // left sandbags
            v[1].Init( 0.0f, 0.3, 0.0f, 0.4, 0.3, 0.0f);
            v[2].Init( 0.4, 0.3, 0.0f, 0.4, 0.0f, 0.0f);
            v[3].Init( 0.0f, 0.2, 0.0f, 0.4, 0.2, 0.0f);
            v[4].Init( 0.0f, 0.1, 0.0f, 0.4, 0.1, 0.0f);
            v[5].Init( 1.0f, 0.0f, 0.0f, 1.0f, 0.3, 0.0f); // right sandbags
            v[6].Init( 1.0f, 0.3, 0.0f, 1.4, 0.3, 0.0f);
            v[7].Init( 1.4, 0.3, 0.0f, 1.4, 0.0f, 0.0f);
            v[8].Init( 1.0f, 0.2, 0.0f, 1.4, 0.2, 0.0f);
            v[9].Init( 1.0f, 0.1, 0.0f, 1.4, 0.1, 0.0f);
            v[10].Init( 0.1, 0.3, 0.0f, 0.1, 1.6, 0.0f); // box
            v[11].Init( 0.1, 1.6, 0.0f, 1.3, 1.6, 0.0f);
            v[12].Init( 1.3, 1.6, 0.0f, 1.3, 0.3, 0.0f);
            v[13].Init( 0.4, 0.0f, 0.0f, 0.4, 1.0f, 0.0f); // door
            v[14].Init( 0.4, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f);
            v[15].Init( 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f);
            v[16].Init( 0.9, 1.6, 0.0f, 0.9, 2.5, 0.0f); // flag
            v[17].Init( 0.9, 2.5, 0.0f, 0.5, 2.5, 0.0f);
            v[18].Init( 0.5, 2.5, 0.0f, 0.5, 2.1, 0.0f);
            v[19].Init( 0.5, 2.1, 0.0f, 0.9, 2.1, 0.0f);
            v[20].Init( 0.4, 1.2, 0.0f, 0.6, 1.2, 0.0f); // window 3
            v[21].Init( 0.6, 1.2, 0.0f, 0.6, 1.3, 0.0f);
            v[22].Init( 0.6, 1.3, 0.0f, 0.4, 1.3, 0.0f);
            v[23].Init( 0.4, 1.3, 0.0f, 0.4, 1.2, 0.0f);
            v[24].Init( 0.8, 1.2, 0.0f, 1.0f, 1.2, 0.0f); // window 4
            v[25].Init( 1.0f, 1.2, 0.0f, 1.0f, 1.3, 0.0f);
            v[26].Init( 1.0f, 1.3, 0.0f, 0.8, 1.3, 0.0f);
            v[27].Init( 0.8, 1.3, 0.0f, 0.8, 1.2, 0.0f);
            width = 2.0;

  // Load MD2 models
  try
    {
     //   string file = "";
     // model = new Md2Model(*file);
    }
  catch (std::runtime_error &err)
    {
      cerr << "Error: failed to load model!" << endl;
    }



            col.Init(1.0f, 1.0f, 1.0f, 1.0f);
            t = WORLD_BUNKER;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            if(x > 0)  life = 100.0; // bad guys
            if(x <= 0) life = -100.0; // good guys
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            break;
        case WORLD_SKY_1:
            size = 0;
            t = WORLD_SKY_1;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            SDL_Surface *bg;
            bg = IMG_Load("../res/sky1.png");
            if(bg->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bg->w, bg->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bg->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(bg);
            break;
        case WORLD_SKY_2:
            size = 0;
            t = WORLD_SKY_2;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            SDL_Surface *bg2;
            bg2 = IMG_Load("../res/sky2.png");
            if(bg2->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bg2->w, bg2->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bg2->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(bg2);
            break;
        case WORLD_SKY_3:
            size = 0;
            t = WORLD_SKY_3;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            SDL_Surface *bg3;
            bg3 = IMG_Load("../res/sky3.png");
            if(bg3->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bg3->w, bg3->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bg3->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(bg3);
            break;
        case WORLD_SKY_4:
            size = 0;
            t = WORLD_SKY_4;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            SDL_Surface *bg4;
            bg4 = IMG_Load("../res/sky4.png");
            if(bg4->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, bg4->w, bg4->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, bg4->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(bg4);
            break;
        case WORLD_GROUND_1:
            size = 0;
            t = WORLD_GROUND_1;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            SDL_Surface *gr1;
            gr1 = IMG_Load("../res/ground1.png");
            if(gr1->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, gr1->w, gr1->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, gr1->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(gr1);
            break;
        case WORLD_GRASS_1:
            size = 0;
            t = WORLD_GRASS_1;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            miracleGrow = 0.0f;
            seed = ((rand()%10000 / 10000.0f) - 0.4f);
            if(seed < 0.2f) seed = 0.2f;
            SDL_Surface *g1;
            g1 = IMG_Load("../res/grass.png");
            if(g1->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, g1->w, g1->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, g1->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(g1);
            break;
        case WORLD_CLOUDS_1:
            size = 0;
            t = WORLD_CLOUDS_1;
            state = STATE_NORM;
            power = 0.0;
            range = 0.0;
            life = 0.0;
            team = TEAM_NEUTRAL;
            pos.Init(x, y, z);
            miracleGrow = 0.0f;
            seed = ((rand()%10000 / 10000.0f) - 0.4f);
            if(seed < 0.2f) seed = 0.2f;
            SDL_Surface *c1;
            c1 = IMG_Load("../res/clouds.png");
            if(c1->w > 0)
                {
                //glDeleteTextures(1, &texture);
                glGenTextures(1, &texture); // lets build the texture!
                glBindTexture(GL_TEXTURE_2D, texture);
                glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, c1->w, c1->h, 0, GL_RGBA, GL_UNSIGNED_BYTE, c1->pixels);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
                glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
                }
            SDL_FreeSurface(c1);
            break;
        default:
            break;
        }

    }

////////////////////////////////////////////////////////////////
// Update() - update one world item
bool World::Update(float d)
    {

    if(t == WORLD_GRASS_1 && miracleGrow < seed)
        {
        miracleGrow += d / 10;
        if(miracleGrow > 0.6f) miracleGrow = 0.6f;
        }
    if(life > 10.0f)
        {
        team = TEAM_BAD;
        col.Init(1.0f, 0.0f, 0.0f, 1.0f);
        }
    else if(life < -10.0f)
        {
        team = TEAM_GOOD;
        col.Init(0.0f, 1.0f, 0.0f, 1.0f);
        }
    else
        {
        team = TEAM_NEUTRAL;
        col.Init(1.0f, 1.0f, 1.0f, 1.0f);
        }
    if(life > 100.0f) life = 100.0f;
    if(life < -100.0f) life = -100.0f;

    return true;

    }

////////////////////////////////////////////////////////////////
// Draw() - draw one world item
void World::Draw()
    {


    //mod.Render();


    // if the size is > 1 it is a texture based item
    if (size < 1)
        {
        glPushMatrix();
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D, texture);
        glColor4f(col.r, col.g ,col.b, col.a);

        // draw the fancy ground
        if(t == WORLD_GROUND_1)
            {
            glBegin(GL_QUADS);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(-150.0f,  0.0f, pos.z);
            glTexCoord2f(0.0f,0.95f);
            glVertex3f(-150.0f, -5.0f, pos.z);
            glTexCoord2f(8.0f,0.95f);
            glVertex3f( 150.0f, -5.0f, pos.z);
            glTexCoord2f(8.0f,0.0f);
            glVertex3f( 150.0f,  0.0f, pos.z);
            glEnd();

            // sprout the grass
            }
        else if(t == WORLD_GRASS_1)
            {
            glBegin(GL_QUADS);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(pos.x,        pos.y + miracleGrow, pos.z);
            glTexCoord2f(0.0f,1.0f);
            glVertex3f(pos.x,        pos.y,               pos.z);
            glTexCoord2f(1.0f,1.0f);
            glVertex3f(pos.x + 1.0f, pos.y,               pos.z);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f(pos.x + 1.0f, pos.y + miracleGrow, pos.z);
            glEnd();

            // draw the sky
            }
        else if((t >= WORLD_SKY_1 && t <= WORLD_SKY_4) || t == WORLD_CLOUDS_1)
            {
            glBegin(GL_QUADS);
            glTexCoord2f(0.0f,0.0f);
            glVertex3f(-180.0f, 75.0f, pos.z);
            glTexCoord2f(0.0f,1.0f);
            glVertex3f(-180.0f,  0.0f, pos.z);
            glTexCoord2f(1.0f,1.0f);
            glVertex3f( 180.0f,  0.0f, pos.z);
            glTexCoord2f(1.0f,0.0f);
            glVertex3f( 180.0f, 75.0f, pos.z);
            glEnd();
            }
        glDisable(GL_TEXTURE_2D);
        glPopMatrix();

        // draw the buildings and land line...
        }
    else
        {
        glPushMatrix();
        glTranslatef(pos.x, pos.y, pos.z); // move to the correct position
        glLineWidth(width);
        glColor4f(col.r, col.g, col.b, col.a);
        glBegin(GL_LINES);
        for(int i = 0; i < size; i++)   // run through the array and draw the World objects
            {
            glVertex3f(v[i].x1, v[i].y1, v[i].z1);
            glVertex3f(v[i].x2, v[i].y2, v[i].z2);
            }
        // draw a life bar, cool
        if(life < 0)
            {
            glColor4f(1.0f, -(life / 100.0f), -((life / 100.0f) / 2), 1.0f);
            glVertex3f(-0.2f, -(life / 100.0f), 0.0f);
            }
        if(life >= 0)
            {
            glColor4f(1.0f, (life / 100.0f), ((life / 100.0f) / 2), 1.0f);
            glVertex3f(-0.2f, (life / 100.0f), 0.0f);
            }
        glVertex3f(-0.2f, 0.0f, 0.0f);
        glEnd();
        glPopMatrix();
        }

    }









